package com.itheima.travel.service.impl;

import com.itheima.travel.mapper.CategoryMapper;
import com.itheima.travel.pojo.Category;
import com.itheima.travel.pojo.CategoryExample;
import com.itheima.travel.req.CategoryVo;
import com.itheima.travel.service.CategoryService;
import com.itheima.travel.utils.BeanConv;
import com.itheima.travel.utils.EmptyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<CategoryVo> findAllCategory() {
        // 创建条件(没有条件)
        CategoryExample example = new CategoryExample();
        List<Category> list = categoryMapper.selectByExample(example);
        // 判断有没有查到数据
        if (!EmptyUtil.isNullOrEmpty(list)){
            // 转成Vo对象
            List<CategoryVo> categoryVos = BeanConv.toBeanList(list, CategoryVo.class);
            return categoryVos;
        }
        return null;
    }
}
